package com.y.mytest.controller;

import com.alibaba.fastjson.JSONObject;
import com.y.mytest.entity.RedisTest;
import com.y.mytest.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;

@RestController
@RequestMapping("/")
public class OpenController {
    @Autowired
    private RedisTest redis;

    @GetMapping("/testHello")
    public Object testHello() {
        System.out.println(new Date());
        //return JSONObject.parseObject("{'key':'昂昂昂'}");
        return JSONObject.toJSON(redis);
    }

    @PostMapping("/testJson/{sum}")
    public User testData(@RequestBody @Valid User user,
                         @RequestParam(value = "id", required = false) String id,
                         @PathVariable("sum") Long sum) {
        System.out.println("id 为null" + id);
        System.out.println("sum" + sum);
        return user;
    }

    @PostMapping("/testForm/{sum}")
    public User testForm(User user,
                         @RequestParam(value = "id", required = false) String id,
                         @PathVariable("sum") Long sum) {
        System.out.println("id" + id);
        System.out.println("sum" + sum);
        return user;
    }
}
